#!/bin/bash

DICT_PATH=~/workspace/hiseg/dict/final
USER_DICT=user

addword()
{
	if [ -z $1 ];then
		echo "USAGE: $0 word [freq]"
		return 1
	fi
	word=$1
	freq=$2
	if [ -z $2 ];then
		freq=1
	fi
	echo "$freq" | grep -qv "[^0-9.]"
	if [ $? -eq 1 ];then
		echo "freq not a num"
		return
	fi
	res=$(grep "\b$word\b" $DICT_PATH/*)
	len=$(echo "$res" |wc -L)
	if [ $len -ne 0 ];then
		echo "aready exist"
		echo $res
		return
	fi
	echo -e "$word\t$freq" >> $DICT_PATH/$USER_DICT
	tail -5 $DICT_PATH/$USER_DICT
}

addword $1 $2
